//
//  DLProducer.m
//  duilian
//
//  Created by shaojinkuang on 6/13/16.
//  Copyright © 2016 shaojinkuang. All rights reserved.
//

#import "DLProducer.h"

#define DLInterface @"CoupletsWS_V2.asmx/GetXiaLian"
@interface DLItem ()
//对联的字典数据源
@property (nonatomic, strong) NSDictionary* DLDic;
@end

@implementation DLItem

- (instancetype)initWithDataDic:(NSDictionary *)dic {
    self = [super init];
    if (self) {
        _DLDic = dic;
    }
    return self;
}
//获取对联SegmentPattern
- (NSString *)getSegmentPattern {
    
    return [self.DLDic valueForKey:@"SegmentPattern"];
}
//获取队列候选词列序列
- (NSArray*)getWordCandidatesInColumnOrder {
    return [self.DLDic valueForKey:@"WordCandidatesInColumnOrder"];
}
//获取所有候选下联
- (NSArray*)getXialianCandidates {
    return [self.DLDic valueForKey:@"XialianCandidates"];
}

@end

@implementation DLProducer

- (void )getAllXiaLianContent:(NSDictionary *)param cb:(contentBlock)cb{
    [byNetworkHelper postJSONWithUrl:DLInterface parameters:param success:^(id responseObject) {
        NSLog(@"it is %@",responseObject);
        NSArray* XialianSystemGeneratedSets = [responseObject valueForKeyPath:@"d.XialianSystemGeneratedSets"];
        NSMutableArray* resultArray = [NSMutableArray array];
        for (NSDictionary* dic in XialianSystemGeneratedSets) {
            DLItem* item = [[DLItem alloc] initWithDataDic:dic];
            [resultArray addObject:item];
        }
        cb(resultArray);
        
    } fail:^{
        
    }];
}
@end
